import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;


public class TestCounter {
	Counter counter;
	ExecutorService executor;
	int NUM=1000;
	
	@Before
	public void initBlock(){
		counter=new Counter();
		executor=Executors.newFixedThreadPool(4);
		
	}
	
	
	@Test
	public void test() {
		for (int i = 0; i < NUM; i++) {
			executor.submit(new Runnable(){
				public void run(){
					counter.incCounter();
				}
			});
			System.out.println(i);
		}
		
	}
	
	@After
	public void checkResult(){
		executor.shutdown();
		System.out.println(counter.getCounter());
		assertEquals(NUM,counter.getCounter());
	}
	

}
